#include "fact_with_mask_searcher.hpp"

#include "../../utils/utils.hpp"

namespace mashine { namespace kb { namespace search {

FactWithMaskSearchVisitor::FactWithMaskSearchVisitor(mashine::kb::Literal predicate) 
		: SearchVisitor<mashine::kb::Literal, mashine::kb::Literal>(predicate)
{
}

std::vector<mashine::kb::Literal> FactWithMaskSearchVisitor::search(mashine::kb::KnowledgeBase * kBase)
{
	std::vector<mashine::kb::Literal> result;
	
	std::vector<mashine::kb::Literal>::const_iterator i;
	for (i = kBase->getFacts().begin(); i != kBase->getFacts().end(); ++i)
	{
		if ( !criteria.getName().compare((*i).getName()) )
		{
			for (int idx = 0; idx < criteria.getParams().size(); ++idx)
			{
				if (utils::is_constant_name(criteria.getParams()[idx]) 
						&& criteria.getParams()[idx].compare((*i).getParams()[idx]))	
					break;
			}
		
			result.push_back(*i);
		}
	}

	return result;
}

}}}